import { Component, Input, OnInit, TemplateRef } from '@angular/core';
import { environment } from '@env/environment';
import { NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-img-preview',
  templateUrl: './img-preview.component.html',
  styleUrls: ['./img-preview.component.less']
})
export class ImgPreviewComponent implements OnInit {
  @Input()
  set imgUrl(value: string){
    this._imgUrl = value.startsWith('http') || value.startsWith('https') || value.startsWith('./') ? value : this._imgUrl = this.serverUrl + value;
  };
  _imgUrl: string;
  canPreview = true;
  serverUrl = environment.SERVER_URL + '/';
  constructor(
    private modal: NzModalService
  ) { }
  ngOnInit() {
  }
  previewImg(tpl: TemplateRef<string>) {
    this.modal.create({
      nzTitle: '图片预览',
      nzContent: tpl,
      nzWidth: '60%',
      nzFooter: null
    })
  }
}
